import jsonpath
import json
obj = json.load(open('store.json','r',encoding='utf8'))
# 所有书的作者
# author_list = jsonpath.jsonpath(obj,'$.store.book[*].author')
# print(author_list)
#所有作者
# author_list = jsonpath.jsonpath(obj,'$..author')
# print(author_list)
#store下面的所有元素
# tag_list = jsonpath.jsonpath(obj,'$.store.*')
# print(tag_list)
#store下面的所有价格
# price_list = jsonpath.jsonpath(obj,'$.store..price')
# print(price_list)
#第三本书
# book = jsonpath.jsonpath(obj,'$..book[2]')
# print(book)
#获取最后一本书
# last_book = jsonpath.jsonpath(obj,'$..book[(@.length-1)]')
# print(last_book)
#获取前面两本书
# book_list = jsonpath.jsonpath(obj,'$..book[0,1]')
# book_list = jsonpath.jsonpath(obj,'$..book[:2]')
# print(book_list)
#过滤条件的书
book_list = jsonpath.jsonpath(obj,'$..book[?(@.isbn)]')
print(book_list)